package com.huihe.sys.controller;

import com.huihe.common.entity.AjaxResult;
import com.huihe.storage.dto.LoginBody;
import com.huihe.framework.service.LoginService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

/**
 * 登录 Controller层
 */
@RestController
@AllArgsConstructor
public class LoginController {

    /**
     * 登录 Service 层
     */
    LoginService loginService;

    /**
     * 登录验证
     * @param loginBody 登录信息
     * @return token
     */
    @PostMapping("/login")
    public AjaxResult login(@RequestBody LoginBody loginBody){
        String token = loginService.login(loginBody);
        Map<String,String> map = new HashMap<>();
        map.put("access_token",token);
        return AjaxResult.success(map);
    }
}
